
<div class="row actions">
    <div class="col-md-12">
        <div class="pull-left">
            <a data-ui-sref="plugins.add"
               ng-if="user.hasPermission($state.name.split('.')[0],'create')"
               class="btn btn-primary">
                <i class="mdi mdi-plus"></i>
                Add global plugins
            </a>
        </div>
        <list-search
                class="pull-right"
                data-filters="filters"
                data-options="itemsPerPageOptions"
                data-items="itemsPerPage"
        ></list-search>
    </div>
</div>


<konga-loader ng-if="loading && !items.data.length"></konga-loader>

<div class="row" ng-if="!loading || items.data.length">

    <div class="col-md-12">
        <div class="table-responsive">
            <table class="table table-hover table-striped">
                <tr>
                    <th width="1"></th>
                    <th width="1" ng-if="user.hasPermission($state.name.split('.')[0],'update')"></th>
                    <th width="1"></th>
                    <th width="{{item.width}}" class="text-nowrap"
                        data-ng-repeat="item in titleItems | filter:titleFilter"
                    >
                        <a
                                data-ng-show="item.column"
                                class="clickable"
                                data-ng-click="changeSort(item)"
                                data-ng-bind-html="item.title.toUpperCase()"
                        ></a>
                        <span
                                data-ng-show="!item.column"
                                data-ng-bind-html="item.title.toUpperCase()"
                        ></span>

                        <i class="mdi"
                           data-ng-show="sort.column == item.column"
                           data-ng-class="{'mdi-chevron-down': !sort.direction, 'mdi-chevron-up': sort.direction}"
                        ></i>
                    </th>
                    <th width="1" ng-if="user.hasPermission($state.name.split('.')[0],'delete')"></th>
                </tr>
                <tr
                        dir-paginate="item in items.data | orderBy:sort.column:sort.direction | filter : filters.searchWord | itemsPerPage: itemsPerPage">
                    <td>
                        <img ng-src="images/kong/plugins/{{item.name}}.png" style="height: 42px">
                    </td>
                    <td ng-if="user.hasPermission($state.name.split('.')[0],'update')">

                        <i class="mdi mdi-toggle-switch text-success clickable"
                           ng-show="item.enabled"
                           ng-click="togglePlugin(item)"
                           uib-tooltip="Enabled"></i>
                        <i class="mdi mdi-toggle-switch-off text-muted clickable"
                           ng-show="!item.enabled"
                           ng-click="togglePlugin(item)"
                           uib-tooltip="Disabled"></i>
                    </td>
                    <td>
                        <raw-view data-item="item"></raw-view>
                    </td>
                    <th><a href ng-click="onEditPlugin(item)">{{item.name}}</a></th>
                    <td>{{::getContext(item)}}</td>
                    <td>
                        <a data-ng-if="item.api_id" data-ui-sref="apis.edit({api_id:item.api_id})">{{item.api_id}}</a>
                        <a data-ng-if="item.service_id" data-ui-sref="services.read({service_id:item.service_id})">{{item.service_id}}</a>
                        <a data-ng-if="item.route_id" data-ui-sref="routes.read({route_id:item.route_id})">{{item.route_id}}</a>
                        <span data-ng-if="!item.api_id && !item.service_id && !item.route_id" > All Entrypoints </span>
                    </td>
                    <td>
                        <a data-ng-if="item.consumer_id" data-ui-sref="consumers.edit({id:item.consumer_id})">{{item.consumer_id}}</a>
                        <span data-ng-if="!item.consumer_id" >All consumers</span>
                    </td>
                    <td>{{item.created_at | date : format : timezone}}</td>

                    <td ng-if="user.hasPermission($state.name.split('.')[0],'delete')">
                        <button type="button" ng-click="deleteItem($index,item)" class="btn btn-danger btn-link">
                            <i class="mdi mdi-delete"></i>
                            Delete
                        </button>
                    </td>
                </tr>
                <tr data-ng-if="items.data.length === 0">
                    <td colspan="100%" class="text-center text-muted">
                        <em>no data found...</em>
                    </td>
                </tr>
            </table>
        </div>
        <dir-pagination-controls></dir-pagination-controls>
    </div>


</div>

